package com.example.mapper;


import com.example.entity.CourseCatalog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CourseCatalogMapper {

    // 使用MyBatis的Mapper接口扫描注解
    @Select("SELECT * FROM CourseCatalog WHERE course_id = #{courseId} ORDER BY `sequence`, level ASC")
    List<CourseCatalog> selectAllByCourseId(@Param("courseId") Long courseId);


    // 使用MyBatis的Mapper接口扫描注解
    @Select("SELECT * FROM CourseCatalog WHERE id = #{id}")
    CourseCatalog selectById(@Param("id") Long id);



    @Insert("INSERT INTO coursecatalog (course_id, parent_id, chapter_title, section_title, content, level, sequence, video) "
            + "VALUES (#{courseId}, #{parentId}, #{chapterTitle}, #{sectionTitle}, #{content}, #{level}, #{sequence}, #{video})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertCourseCatalog(CourseCatalog courseCatalog);
    @Select("SELECT MAX(id) FROM coursecatalog")
    Integer findMaxId();
    // 在CourseCatalogMapper中添加更新方法
    @Update("UPDATE coursecatalog SET " +
            "parent_id = #{parentId}, " +
            "chapter_title = #{chapterTitle}, " +
            "section_title = #{sectionTitle}, " +
            "content = #{content}, " +
            "level = #{level}, " +
            "sequence = #{sequence}, " +
            "video = #{video} " +
            "WHERE id = #{id}")
    void updateByPrimaryKey(CourseCatalog courseCatalog);
    @Delete("DELETE FROM coursecatalog WHERE id = #{id}")
    void deleteByPrimaryKey(Long id);
}
